package com.drcoffee.drcoffeemall.mapper;

import com.drcoffee.drcoffeemall.entry.Attachment;
import com.drcoffee.drcoffeemall.entry.Giveaway;
import com.drcoffee.drcoffeemall.entry.SpecialPrice;
import com.drcoffee.drcoffeemall.entry.search.PartSearch;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Mapper
@Repository
public interface PartsMapper {
    List<Attachment> getAttachment(PartSearch partSearch);

    List<Attachment> getAttachmentNoType(PartSearch partSearch);

    List<Attachment> getAttachmentMain(PartSearch partSearch);

    Attachment getAttachmentById(String language, String part_code, String price_type);

    List<String> getDots(Integer dot_id);

    Attachment getAttachmentByPartCode(String part_code, String price_type, String language);

    Attachment getAttachmentByCode(String price_type, String part_code, String language);

    @Select("SELECT * FROM t_special_price WHERE erp_code = #{erp_code}")
    List<SpecialPrice> getSpecialPrice(String erp_code);

    @Select("SELECT a.* ${NonPartsSql} FROM t_attachment a LEFT JOIN t_attachment_price b ON a.part_code = b.part_code WHERE a.type = 'N' AND (a.part_code LIKE #{serach} OR a.part_name LIKE #{serach})")
    List<Attachment> getNonParts(String serach,String NonPartsSql);

    @Select("SELECT * FROM t_giveaway WHERE p_code = #{partCode}")
    Giveaway getGiveawayByPartCode(String partCode);

    List<Attachment> getPartsByCodes(String price_type, String language, List<String> partCodes);

    List<Giveaway> getPartCodesBySatisfyGiveaway(String account, String source, List<String> partCodes);

    @Select("SELECT part_code FROM t_special_price WHERE erp_code = #{erpCode}")
    List<String> getSpecialPricePartCodes(String erpCode);


}

